package com.qs.questionnairesurveysystem.mapper;

import com.qs.questionnairesurveysystem.entity.Answer;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnswerMapper {

    // 插入新答案
    @Insert("INSERT INTO answers (surveyId, questionId, respondent,respondentId, content, isValid) VALUES (#{surveyId}, #{questionId}, #{respondent},#{respondentId}, #{content}, #{isValid})")
    void insertAnswer(Answer answer);

    // 更新答案
    @Update("UPDATE answers SET content = #{content}, isValid = #{isValid} WHERE answerId = #{answerId}")
    void updateAnswer(Answer answer);

    // 删除答案
    @Delete("DELETE FROM answers WHERE answerId = #{answerId}")
    void deleteAnswer(Long answerId);

    // 获取指定答案
    @Select("SELECT * FROM answers WHERE answerId = #{answerId}")
    Answer getAnswerById(Long answerId);

    // 获取所有答案
    @Select("SELECT * FROM answers")
    List<Answer> getAllAnswers();

    // 根据问卷ID获取答案
    @Select("SELECT * FROM answers WHERE surveyId = #{surveyId}")
    List<Answer> getAnswersBySurveyId(Long surveyId);

    // 根据问题ID获取答案
    @Select("SELECT * FROM answers WHERE questionId = #{questionId}")
    List<Answer> getAnswersByQuestionId(Long questionId);

    @Select("SELECT * FROM answers WHERE surveyId = #{surveyId} and respondentId = #{uid}")
    List<Answer> getAnswersBySurveyIdUid(Long surveyId, Long uid);
}
